package com.leet.string;

import java.util.HashSet;
import java.util.Set;

public class LengthOfLongestSubstring {
    public int lengthOfLongestSubstring(String s) {
        int ans = 0;
        String tmp;
        //if(s==" ") return 1;
        for(int i = 0;i < s.length(); i++){
            Set<Character> vis = new HashSet<>();
            for(int j = i; j < s.length();j++){
                char c = s.charAt(j);
                if(c == ' ') c = '*';
                if(vis.contains(c)){
                    tmp = s.substring(i,j);
                    if(tmp.length() > ans){
                        ans = tmp.length();
                    }
                    break;
                }
                vis.add(c);
                ans = vis.size();
            }
        }
        return ans;
    }

    public static void main(String[] args) {
        LengthOfLongestSubstring lengthOfLongestSubstring = new LengthOfLongestSubstring();
        int i = lengthOfLongestSubstring.lengthOfLongestSubstring(" ");
        System.out.println(i);
    }
}
